package com.tim.shadow.lib.image;

import java.lang.ref.SoftReference;
import java.util.HashMap;

import com.tim.shadow.lib.util.MD5;
/*
 * Author: poper Email:xut@bluemobi.cn
 * Created Date:2013-4-16
 * Copyright @ 2013 BU
 * Description: 类描述
 *
 * History:
 */

import android.content.Context;
import android.graphics.Bitmap;

public class TImageCache {
	private HashMap<String, SoftReference<Bitmap>> mBitmapCache;

	public TImageCache() {
		mBitmapCache = new HashMap<String, SoftReference<Bitmap>>();
	}

	public Bitmap getImageBitMap(Context context, String url) {
		Bitmap bitmap = null;
		SoftReference<Bitmap> bpReference = mBitmapCache.get(MD5.Md5(url));
		if (null != bpReference) {// 如果使用过此url
			bitmap = bpReference.get();// 获取软引用的
		}
		if (null == bitmap) {
			bitmap = TImageGetter.getLocalImage(context, url);// 获取本地的
		}
		if (null == bitmap) {
			bitmap = TImageGetter.getNetImage(context, url);// 获取网络的
		}
		return bitmap;
	}

	public HashMap<String, SoftReference<Bitmap>> getmBitmapCache() {
		return mBitmapCache;
	}
}
